function leap % logistic eq: leapfrog % y' = ry(1-y) with y(0) = y0 ' % clear all previous variables and plots clear * clf % set parameters for problem M=10; r=10; t0=0; y0=0.1; tmax=1; % calculate and plot exact solution tt=linspace(t0,tmax,100); a0=(1-y0)/y0; for it=1:100 exact(it)=1/(1+a0*exp(-r*tt(it))); end; plot(tt,exact,'--k') hold on % define legend and axes used in plot xlabel('t-axis','FontSize',14,'FontWeight','bold') ylabel('Solution','FontSize',14,'FontWeight','bold') title(['Logistic Equation: M = ', int2str(M)],'Color','k','FontSize',14,'FontWeight','bold') % have MATLAB use certain plot options (all are optional) box on axis([0 tmax -2 2]) % Set the fontsize to 14 for the plot set(gca,'FontSize',14); % calculate leapfrog solution t=linspace(t0,tmax,M+1); h=t(2)-t(1); y=y0; yy=1/(1+a0*exp(-r*h)); leap=[y, yy]; ts=[0 h]; for i=3:M+1 yyy=y+2*r*h*yy*(1-yy); leap=[leap, yyy]; ts=[ts t(i)]; y=yy; yy=yyy; plot(ts,leap,'-or','LineWidth',1) if i==3 legend(' Exact',' Leap',2) % Set legend font to 14/bold set(findobj(gcf,'tag','legend'),'FontSize',14,'FontWeight','bold'); end; pause(1); end; hold off